use serde::{Deserialize, Serialize};
use struct_field_names_as_array::FieldNamesAsSlice;
use crate::core::serialize_tools::empty_string_as_none;


// 错误信息
#[derive(Deserialize, Serialize)]
pub struct ErrorReq {
    pub error: String
}

/// 下拉选项
#[derive(sqlx::FromRow, Deserialize, Serialize, FieldNamesAsSlice)]
pub struct OptionRow { 
    pub id: i64,
    pub name: String, 
}

/// 分类
#[derive(sqlx::FromRow, Deserialize, Serialize, FieldNamesAsSlice)]
pub struct TypeRow { 
    pub id: i64,
    pub name: String, 
    pub image: String, 
    pub num: i64 
}

// 基本分页请求
#[derive(Deserialize, Serialize)]
pub struct PageListReq {
    /// 当前页
    pub page: Option<i64>,
    /// 每页数量
    pub page_size: Option<i64>
}

// 基本分页请求
#[derive(Deserialize, Serialize)]
pub struct CategoryListReq {
    /// 当前页
    pub page: Option<i64>,
    /// 每页数量
    pub page_size: Option<i64>,
    #[serde(default, deserialize_with = "empty_string_as_none")]
    pub cid: Option<i64>
}

pub struct Breadcrumb {
    pub title: String,
    pub sub_title: String
}
